Xlet Resource Budgets
The resource constraints of an Xlet can be defined in the xlet.properties file, or by including a file xlet.budgets into the Xlet’s jar file before the file is signed. Properties in xlet.properties take precedence over properties in xlet.budgets. The budgets file has the format of a Java properties file specified in the Java API.
Example:
Properties:
A value of 0 is not permitted and will cause an error when starting the Xlet.
If an Xlet attempts to exceed the number of threads permitted for it, calls to Thread.start() will result in an exception, e.g.,
java.lang.Error: ThreadGroup is limited to 10 threads, contains 10, so add is not allowed.
An Xlet may create an arbitrary number of instances of class java.lang.Thread, and there is no limit on the number of calls to start() on these threads. However, the number of threads that may be alive simultaneously is limited by this property. To be sure that a thread is no longer alive, a call to Thread.join() is required. Before a call to Thread.join(), the thread may have finished its Java execution, but it may still not have been released back to the AMS’s thread pool.
Note that the number or threads specified here includes all threads that are created internally by the AMS, LWUIT graphics, standard libraries, etc. An Xlet has at least two internal threads, one for starting, pausing, and stopping the xlet, and one of LWUIT graphics. So, to allow the creation of one additional thread by the Xlet, this budget has to be set to 3 or higher.
Determining Number of Xlet Threads for your app
Sensor - 6 (i.e. 1 + 5 different PPS Objects)
Hence even if we say that the Sensors API uses 6 threads, but if an application uses the sensors to any one of the 5 groups listed above, in that case only 2 threads will be created by the sensors implementation.
WMA - 1
RMS - 1
OpenNav - 1
VR – 1
Location - 2
IXC also generates a thread to service every remote request that is created. So if your Xlet generates 3 simultaneous requests, 3 threads will be generated. Once each request is complete, the thread is destroyed.
DeviceInputImpl, will genereate a thread to help manager scroll knob events. The thread is created to buffer the amount of events received and then destroyed after all of the events have been dispatched.
CPU budgets for an Xlet are enabled, if the property xlet.period is defined. If xlet.timeBudget.paused or xlet.timeBudget.running is defined, then xlet.period must also be defined.
xlet.timeBudget = [m]s/[m]s \ {, [m]s/[m]s } (Required)
The time budget is specified as a budget of CPU time that is permitted over a given interval of time. Both, budget and interval can be specified in seconds (s) or microseconds (ms). To permit an Xlet to use 50% of the CPU time over a 10 seconds interval, you can specify 5s/10s. It is possible to specify several budgets and corresponding intervals, such that, e.g., short term CPU usage peaks can be permitted while longer term usage can be restricted.
For example, specifying 900ms/1s,10s/100s would permit 90% CPU usage during any second, but will limit the long term CPU usage to 10% over a 100 seconds interval.
In order to establish a counter-measure against an Xlet that exceeds a defined time budget, xlet.priorityIfTimeBudgetExceeded must be defined.
xlet.priorityIfTimeBudgetExceeded = 0 (Required)
xlet.period = <n> (Required)
Start with 1 second.
xlet.timeBudget.paused = <n> (Required)
Start with 300ms.
xlet.timeBudget.running = <n> (Required)
Start with 800ms.